import java.util.Arrays;
import java.util.Scanner;

public class Anagram {
        
	public static void main(String[] args) {
		Scanner inputUserData = new Scanner(System.in);
		String firstString = new String();
		String Anagram = new String();
		System.out.println("Enter the 1st string: ");
		if(inputUserData.hasNextLine()){
			firstString = inputUserData.nextLine();
			}
		System.out.println("Enter the 2nd string: ");
		if(inputUserData.hasNextLine()){
			Anagram = inputUserData.nextLine();
			}
		firstString = firstString.toLowerCase();
		Anagram = Anagram.toLowerCase();
		if ( firstString.length() != Anagram.length() ) {
			System.out.print("Not an anagram(unequal strings length) ");		
        }else{
        char[] arrayFromFirstString = firstString.toCharArray();
        char[] arrayFromAnagramString = Anagram.toCharArray();
        Arrays.sort(arrayFromFirstString);
        Arrays.sort(arrayFromAnagramString);
        String sorted1 = Arrays.toString(arrayFromFirstString);
        String sorted2 = Arrays.toString(arrayFromAnagramString);
        if(sorted1.equals(sorted2)){
        	System.out.print("Anagram ");
        	}else{
        		System.out.print("Not an anagram ");
        		}
        }
		}
	}

